﻿
 //example:
 //var m = new myFlash('tmp.swf',300,300);
 //m.addParam("参数名","参数值");
 //m.addAttrib("属性名","属性值");
 //m.addVars("变量名","变量值");
 //m.toObject('要输出的对象ID');
var myFlash = function(src,w,h,v){
    this.src    = src;
    this.w      = w;
    this.h      = h;
    this.v      = (v)?v:"8.0.35.0";
    this.params = new Array();
    this.attribs= new Array();
    this.vars   = new Array();
}
myFlash.prototype.addParam = function(n,v){this.params[n] = v;}
myFlash.prototype.addAttrib= function(n,v){this.attribs[n] = v;}
myFlash.prototype.addVars  = function(n,v){this.vars[n]=v;}
myFlash.prototype.getFlash = function(){
    var o = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+ this.v +'"';
    var b = '<embed pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"';
    o += ' width="'+ this.w +'" height="'+ this.h +'"';
    b += ' width="'+ this.w +'" height="'+ this.h +'" src="'+ this.src +'"';
     
    for(i in this.attribs)
    {
        o += " ";
        o += i;
        o += '="' + this.attribs[i] + '"';
        
        b += " ";
        b += i;
        b += '="' + this.attribs[i] + '"';
    }
    
    o += '>';
    
    for(i in this.params)
    {
        o += '<param name="'+ i +'" value="'+ this.params[i] +'" />';
    
        b += " ";
        b += i;
        b += '="' + this.params[i] + '"';
    }
    o += '<param name="movie" value="'+ this.src +'" />';
    
    var vs = "";
    for(i in this.vars)
    {
        vs += '&' + i;
        vs += '=' + this.vars[i];
    }
    
    if (vs != "")
    {
        vs = vs.substr(1);
        o += '<param name="FlashVars" value="'+ vs +'" />';
        b += ' FlashVars="' + vs + '"';
    }
    
    b += '></embed>';
    
    o += b;
    o += '</object>';
    
    return o;
}
myFlash.prototype.toObject = function(obj){
    if (typeof obj == 'string') obj = document.getElementById(obj);
    if (!obj){
        alert('Not Find myFlash toObject is args obj;');
        return;
    }
    obj.innerHTML = this.getFlash();
}